//1、命名空间注册工具类   
var Namespace = new Object();
Namespace.register = function(path){
    var arr = path.split(".");
    var ns = "";
    for(var i=0;i<arr.length;i++){
        if(i>0) ns += ".";
        ns += arr[i];
        eval("if(typeof(" + ns + ") == 'undefined') " + ns + " = new Object();");
    }
}
//2、注册命名空间com.zzwtec.community     
Namespace.register("com.zzwtec.community");
//3、使用命名空间      
com.zzwtec.community.CommunityList = function(){
     this.popCommunityList = pop_community_list;
     this.data = {};
}

com.zzwtec.community.BuildList = function(){
    this.popBuildList = pop_build_list;
    this.data = {};
}

com.zzwtec.community.CellList = function(){
    this.popCellList = pop_cell_list;
    this.data = {};
}

com.zzwtec.community.CellList2 = function(){
    this.popCellList = pop_cell_list2;
    this.data = {};
    this.callback = function(){
    	console.log('callback等待赋值');
    };
}

com.zzwtec.community.AreaList = function(){
    this.popAreaList = pop_area_list;
    this.data = {};
}

com.zzwtec.community.permissionNames = function(){
	this.setNameList = setNameList;
	this.getNameList = getNameList;
    this.data = {};
}

//var propertyId;
//var adminId;
 /**
 * 调用该函数实现弹出小区列表，实现回填当前域的功能
 * 点击选中小区文本框  $('input.form-select[name$=communityName]') * 
 */
var pop_community_list = function(data){
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/community/backfill", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择小区',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

/**
 * 调用该函数实现弹出楼栋列表，实现回填当前域的功能
 */
var pop_build_list = function(data){
	buildList.data = data;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/build/backfill", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择楼栋',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

/**
 * 调用该函数实现弹出单元列表，实现回填当前域的功能
 */
var pop_cell_list = function(){
	var data = {};	
	data.buildId = cellList.buildId;
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/cell/backfill", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择单元',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

/**
 * 调研该函数实现弹出用户单元列表，实现回填当前与的功能
 * 点击选中小区文本框  $('input.form-select[name$=cellName]')
 */
var pop_cell_list2 = function(data){	
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/cell/backfill2", function(htmlText){
		indexLayer = layer.open({
	        type: 1,
	        title: '请选择住户单元',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	    cellList2.callback(data);
	});
}

/**
 * 调用该函数实现弹出小区列表，实现回填当前域的功能
 */
var pop_area_list = function(){
	var data = {};
	var areaWidth = $('div.viewFramework-work-area').width();
	doDataPost(data, false, ctx+"/common/area/backfill", function(htmlText){
		cellList2.indexLayer = layer.open({
	        type: 1,
	        title: '请选择区域',
	        offset: ['56px',($(window).width()-areaWidth)+'px'],
	        area: [areaWidth+'px', 'auto'],
	        content: htmlText //注意，如果str是object，那么需要字符拼接。
		});
		$('.layui-layer-content').css('height','auto');
	});
}

var setNameList = function(names){
	this.nameList = names; 
}

var getNameList = function(){
	return this.nameList; 
}


var communityList = new com.zzwtec.community.CommunityList();
var buildList = new com.zzwtec.community.BuildList();
//支持单选回填
var cellList = new com.zzwtec.community.CellList();
//支持多选回填
var cellList2 = new com.zzwtec.community.CellList2();
var areaList = new com.zzwtec.community.AreaList();
var permissionList = new com.zzwtec.community.permissionNames();
